package PrototypePattern;

import java.io.*;
import java.util.*;

/**
 * 
 */
public class Chart implements Serializable, java.io.Serializable {
    @Serial
    private static final long serialVersionUID = 1L; // 添加序列化版本号

    /**
     * Default constructor
     */
    public Chart() {
    }

    /**
     * 
     */
    private String id;
    private String date;
    private String color;
    private DataSet dataSet;

    /**
     * @param id 
     * @param date 
     * @param color 
     * @param dataSet
     */
    public Chart(String id, String date, String color, DataSet dataSet) {
        // TODO implement here
        this.id = id;
        this.date = date;
        this.color = color;
        this.dataSet = dataSet;
    }

    /**
     * @return
     */
    public String getId() {
        // TODO implement here
        return id;
    }

    /**
     * @param id 
     * @return
     */
    public void setId(String id) {
        // TODO implement here
        this.id = id;
    }

    /**
     * @return
     */
    public String getDate() {
        // TODO implement here
        return date;
    }

    /**
     * @param date 
     * @return
     */
    public void setDate(String date) {
        // TODO implement here
        this.date = date;
    }

    /**
     * @return
     */
    public String getColor() {
        // TODO implement here
        return color;
    }

    /**
     * @param color 
     * @return
     */
    public void setColor(String color) {
        // TODO implement here
        this.color = color;
    }

    /**
     * @param dataSet 
     * @return
     */
    public void setDataSet(DataSet dataSet) {
        // TODO implement here
        this.dataSet = dataSet;
    }

    /**
     * @return
     */
    public DataSet getDataSet() {
        // TODO implement here
        return dataSet;
    }
    
    public Chart deepClone() {
        try {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            ObjectOutputStream oos = new ObjectOutputStream(baos);
            oos.writeObject(this);

            ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
            ObjectInputStream ois = new ObjectInputStream(bais);
            return (Chart) ois.readObject();
        } catch (IOException | ClassNotFoundException e) {
            e.printStackTrace();
            return null;
        }
    }

}